#ifndef IMGUI_MANAGER_H
#define IMGUI_MANAGER_H

#include <functional>
#include <memory>
#include <string>
#include <thread>
#include <vector>

class Control
{
    friend class ImGuiManager;

  public:
    Control(std::string _name) : name(_name) {}
    virtual ~Control() = default;

  protected:
    std::string name;
    virtual void Show() = 0; // 纯虚函数，子类必须实现
};

class CustomControl : public Control
{
  public:
    CustomControl(std::string _name) : Control(_name) {}
    ~CustomControl();
    void setShow(std::function<void()> _func);

  protected:
    void Show() override;
    std::function<void()> show;
};

class ImGuiManager
{
  public:
    void Init(int _width, int _height);                // 初始化 ImGui/ImPlot
    void AddControl(std::shared_ptr<Control> control); // 添加控件
    void Show();                                       // 显示所有控件
    void Run();                                        // 开线程来循环执行 Show()

    void addTimeFunc(std::function<void()> _func);

  private:
    int width;
    int height;
    std::vector<std::shared_ptr<Control>> controls;
    std::thread renderThread;
    bool running = false;

    std::vector<std::function<void()>> timeFunc;
};

#endif // IMGUI_MANAGER_H